home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 11 / FM Towns Free Software Collection 11.iso / t_os / tool / artemis1 / src / menumake.awk < prev    next >
Encoding:
AWK Script  |  1993-10-17  |  12.2 KB  |  532 lines

  1. # メニュー定義コンパイル
  2.  
  3. BEGIN {
  4.     token_init()
  5.     if (match(FILENAME, /\..?.?.?$/))
  6.         outfile = substr(FILENAME, 1, RSTART-1) ".md"
  7.     else
  8.         outfile = FILENAME ".md"
  9.     print "ARTemis メニュー定義コンパイル"
  10.     print "(output to: " outfile ")"
  11.     print "" >outfile
  12.     do {
  13.         t = token_get()
  14.         if (t == "menubegin")
  15.         {
  16.             read_menu();
  17.             if (itemidnum > 0)
  18.             {
  19.                 for (i=0; i<itemidnum; i++)
  20.                  { printf("#define %s %s\n",itemidstr[i],itemidid[i]) >> outfile }
  21.                 printf("\n") >> outfile
  22.             }
  23.             if (letnum > 0)
  24.             {
  25.                 for (i=0; i<letnum; i++)
  26.                  { printf("#define %s %s\n",letstr[i],letcon[i]) >>outfile }
  27.                 printf("\n") >>outfile
  28.             }
  29.             if (buttonnum > 0)
  30.             {
  31.                 output_buttons(menuname "_buttons")
  32.                 printf("\n") >>outfile
  33.             }
  34.             if (barnum > 0)
  35.             {
  36.                 output_scrollbars(menuname "_bars")
  37.                 printf("\n") >>outfile
  38.             }
  39.             if (selnum > 0)
  40.             {
  41.                 for (i=0; i<selnum; i++)
  42.                 {
  43.                     output_selector_elements(i, sprintf("%s_selelm%d",menuname,i))
  44.                 }
  45.                 output_selectors(sprintf("%s_sels",menuname),
  46.                                  sprintf("%s_selelm",menuname))
  47.                 printf("\n") >>outfile
  48.             }
  49.             printf("static MENU %s =\n",menuname) >>outfile
  50.             printf("{\n") >>outfile
  51.             printf("\t\"%s\",\n", menutitle) >>outfile
  52.             printf("\t%s,%s,\n", menuxlen,menuylen) >>outfile
  53.             if (buttonnum > 0) { printf("\t%s_buttons,\n", menuname) >>outfile}
  54.             else { printf("\tNULL,\n") >>outfile }
  55.             if (barnum > 0) { printf("\t%s_bars,\n", menuname) >>outfile }
  56.             else { printf("\tNULL,\n") >>outfile }
  57.             if (selnum > 0) { printf("\t%s_sels,\n", menuname) >>outfile }
  58.             else { printf("\tNULL,\n") >>outfile }
  59.             printf("\tNULL,NULL,NULL,\n") >>outfile
  60.             printf("\t%s,\n", menudispfunc) >>outfile
  61.             printf("\t%s,\n", menuerasefunc) >>outfile
  62.             printf("\t0,0,0,0,NO,NO,NULL\n};\n\n") >>outfile
  63.             if (letnum > 0)
  64.             {
  65.                 for (i=0; i<letnum; i++)
  66.                  { printf("#undef %s\n",letstr[i]) >>outfile }
  67.                 printf("\n") >>outfile
  68.             }
  69.         }
  70.         else if (t == "buttonbegin")
  71.         {
  72.             nam = token_get();
  73.             buttonnum = 0;
  74.             while (token_checknext() != "buttonend")
  75.                 { read_button(buttonnum); buttonnum++; }
  76.             token_get(); # skip "buttonend"
  77.             output_buttons(nam)
  78.             printf("\n") >>outfile
  79.         }
  80.         else if (t == "barbegin")
  81.         {
  82.             nam = token_get();
  83.             barnum = 0;
  84.             while (token_checknext() != "barend")
  85.                 { read_scrollbar(barnum); barnum++; }
  86.             token_get(); # skip "barend"
  87.             output_scrollbars(nam);
  88.             printf("\n") >>outfile
  89.         }
  90.         else if (t == "selelementbegin")
  91.         {
  92.             nam = token_get();
  93.             selenum[nam] = 0;
  94.             while (token_checknext() != "selelementend")
  95.                 { read_selector_element(nam, selenum[nam]); selenum[nam]++; }
  96.             token_get(); # skip "selelementend"
  97.             output_selector_elements(nam, nam);
  98.             printf("\n") >>outfile
  99.         }
  100.         else if (t == "selectorbegin")
  101.         {
  102.             nam = token_get()
  103.             selnum = 0
  104.             while (token_checknext() != "selectorend")
  105.                 { read_selector(selnum); selnum++; }
  106.             token_get();
  107.             for (i=0; i<selnum; i++)
  108.              { output_selector_elements(i, sprintf("%s_selelm%d",nam,i)) }
  109.             output_selectors(nam,sprintf("%s_selelm",nam))
  110.             printf("\n") >>outfile
  111.         }
  112.     } while (fileend == 0);
  113.     exit
  114. }
  115.  
  116. func error()
  117. {
  118.     printf("error! near line:%d\n",NR);
  119.     exit
  120. }
  121.  
  122. #-----------------------------------------------------
  123. #             メニュー単位での読み込み
  124. #-----------------------------------------------------
  125.  
  126. func read_menu()
  127. # menubegin の次から、menuend までを読む
  128. {
  129.     buttonnum = 0;
  130.     barnum = 0;
  131.     selnum = 0;
  132.     letnum = 0;
  133.     itemid = 1;
  134.     itemidnum = 0;
  135.     menuname = token_get();
  136.     menudispfunc = "NOFNC"
  137.     menuerasefunc = "NOFNC"
  138.     do {
  139.         t = token_get();
  140.         if (t == "size")
  141.             { menuxlen=token_get(); menuylen=token_get(); continue; }
  142.         else if (t == "title")
  143.             { menutitle=token_get(); continue; }
  144.         else if (t == "let")
  145.         {
  146.             letstr[letnum] = token_get();
  147.             letcon[letnum] = token_get();
  148.             letnum++;
  149.         }
  150.         else if (t == "button")
  151.         {
  152.             if (token_checknext() != "[")
  153.              { read_button(buttonnum); buttonnum++; }
  154.             else
  155.             {
  156.                 token_get(); # [
  157.                 while (token_checknext() != "]")
  158.                     { read_button(buttonnum); buttonnum++; }
  159.                 token_get(); # ]
  160.             }
  161.         }
  162.         else if (t == "scrollbar")
  163.         {
  164.             if (token_checknext() != "[")
  165.              { read_scrollbar(barnum); barnum++; }
  166.             else
  167.             {
  168.                 token_get(); # [
  169.                 while (token_checknext() != "]")
  170.                     { read_scrollbar(barnum); barnum++; }
  171.                 token_get(); # ]
  172.             }
  173.         }
  174.         else if (t == "selector")
  175.         {
  176.             if (token_checknext() != "[")
  177.              { read_selector(selnum); selnum++; }
  178.             else
  179.             {
  180.                 token_get(); # [
  181.                 while (token_checknext() != "]")
  182.                     { read_selector(selnum); selnum++; }
  183.                 token_get(); # ]
  184.             }
  185.         }
  186.         else if (t == "dispfunc")
  187.             menudispfunc=token_get();
  188.         else if (t == "erasefunc")
  189.             menuerasefunc=token_get();
  190.         else if (t == "menuend")
  191.             break;
  192.         else
  193.         {
  194.             print "near line " NR ": invalid menu definition"
  195.             exit
  196.         }
  197.     } while (fileend == 0);
  198. }
  199.  
  200. #-----------------------------------------------------
  201. #             ボタン情報の読み込みと出力
  202. #-----------------------------------------------------
  203.  
  204. func read_button(n)
  205. # ボタン定義の [ から ] までを読む
  206. # 結果はボタン配列の要素 n に格納する
  207. {
  208.     btnx[n] = "0"
  209.     btny[n] = "0"
  210.     btnxlen[n] = "0"
  211.     btnylen[n] = "0"
  212.     btntype[n] = "typeOTHER"
  213.     btnarg[n] = "0"
  214.     btndispfunc[n]= "NOFNC"
  215.     btnavail[n] = "NO"
  216.     btnid[n] = "0"
  217.     if (token_checknext() != "[")
  218.         return;
  219.     token_get(); # [
  220.     while (1) {
  221.         t = token_get();
  222.         if (t == "]")
  223.             break;
  224.         else if (t == "locate")
  225.             { btnx[n] = token_get(); btny[n] = token_get(); }
  226.         else if (t == "size")
  227.             { btnxlen[n] = token_get(); btnylen[n] = token_get(); }
  228.         else if (t == "pict")
  229.             { btntype[n]="typePIC"; btnarg[n]=token_get(); }
  230.         else if (t == "box")
  231.             { btntype[n]="typeBOX"; btnarg[n]=token_get(); }
  232.         else if (t == "buttons" || t == "button")
  233.             { btntype[n]="typeBUTTONS"; btnarg[n]="(int)" token_get(); }
  234.         else if (t == "dispfunc")
  235.             { btndispfunc[n]=token_get(); }
  236.         else if (t == "noselect")
  237.             { btnavail[n] = "YES"; }
  238.         else if (t == "id")
  239.         {
  240.             itemidstr[itemidnum] = token_get();
  241.             btnid[n] = itemidstr[itemidnum]
  242.             itemidid[itemidnum] = itemid;
  243.             itemidnum++;
  244.             itemid++;
  245.         }
  246.         else if (t == "string")
  247.         {
  248.             btntype[n]="typeSTR";
  249.             s = token_get();
  250.             if (s=="boxed")
  251.                 { btntype[n]="typeSTRb"; s=token_get();
  252.                   btnxlen[n]=length(s)*6+6; btnylen[n]=12+4; }
  253.             else if (s=="emphasized" || s=="doubled")
  254.                 { btntype[n]="typeSTRe"; s=token_get(); }
  255.             btnarg[n] = "(int)\"" s "\""
  256.         }
  257.         else
  258.         {
  259.             print "near line " NR ": invalid button definition"
  260.             exit
  261.         }
  262.     }
  263. }
  264.  
  265. func output_buttons(name)
  266. {
  267.     printf("static BUTTON %s[] =\n", name) >>outfile
  268.     printf("{\n") >>outfile
  269.     for (i=0; i<buttonnum; i++)
  270.     {
  271.         printf("\t{%s,%s,", btnx[i],btny[i]) >>outfile
  272.         printf("%s,%s,", btnxlen[i],btnylen[i]) >>outfile
  273.         printf("%s,%s,",btntype[i],btnarg[i]) >>outfile
  274.         printf("%s,%s,", btndispfunc[i],btnavail[i]) >>outfile
  275.         printf("NULL,%s},\n", btnid[i]) >>outfile
  276.     }
  277.     printf("\t{-1}\n") >>outfile
  278.     printf("};\n") >>outfile
  279. }
  280.  
  281. #-----------------------------------------------------
  282. #          スクロールバー情報の読み込みと出力
  283. #-----------------------------------------------------
  284.  
  285. func read_scrollbar(n)
  286. # from [ to ]
  287. {
  288.     barx[n] = "0"
  289.     bary[n] = "0"
  290.     barlen[n] = "0"
  291.     bartype[n] = "barHORI"
  292.     barallsize[n] = "60";
  293.     bardspsize[n] = "5";
  294.     bardsppos[n] = "0";
  295.     barfunc[n]="NOFNC"
  296.     barinv[n]="NO"
  297.     bardispnum[n]="NO"
  298.     baroffset[n]="0"
  299.     barid[n] = "0"
  300.  
  301.     if (token_checknext() != "[")
  302.         return;
  303.     token_get(); # [
  304.     while (1) {
  305.         t = token_get();
  306.         if (t == "]")
  307.             break;
  308.         else if (t == "locate")
  309.             { barx[n] = token_get(); bary[n] = token_get(); }
  310.         else if (t == "size")
  311.             { barlen[n] = token_get(); }
  312.         else if (t == "vert" || t == "vertical")
  313.             { bartype[n]="barVERT" }
  314.         else if (t == "hori" || t == "horisontal")
  315.             { bartype[n]="barHORI" }
  316.         else if (t == "allsize")
  317.             { barallsize[n] = token_get(); }
  318.         else if (t == "dspsize")
  319.             { bardspsize[n] = token_get(); }
  320.         else if (t == "dsppos")
  321.             { bardsppos[n] = token_get(); }
  322.         else if (t == "barfunc")
  323.             { barfunc[n]=token_get(); }
  324.         else if (t == "inverse")
  325.             { barinv[n]="YES"; }
  326.         else if (t == "dispnum")
  327.             { bardispnum[n]="YES"; }
  328.         else if (t == "offset")
  329.             { baroffset[n]=token_get(); }
  330.         else if (t == "id")
  331.         {
  332.             barid[n] = itemidstr[itemidnum] = token_get();
  333.             itemidid[itemidnum] = itemid;
  334.             itemidnum++;
  335.             itemid++;
  336.         }
  337.         else
  338.         {
  339.             print "near line " NR ": invalid scrollbar definition"
  340.             exit
  341.         }
  342.     }
  343. }
  344.  
  345. func output_scrollbars(name)
  346. {
  347.     printf("static SCROLLBAR %s[] =\n", name) >>outfile
  348.     printf("{\n") >>outfile
  349.     for (i=0; i<barnum; i++)
  350.     {
  351.         printf("\t{%s,%s,", barx[i],bary[i]) >>outfile
  352.         printf("%s,", bartype[i]) >>outfile
  353.         printf("%s,", barlen[i]) >>outfile
  354.         printf("%s,%s,%s,",
  355.                barallsize[i],bardspsize[i],bardsppos[i]) >>outfile
  356.         printf("%s,", barfunc[i]) >>outfile
  357.         printf("%s,%s,",bardispnum[i],baroffset[i]) >>outfile
  358.         printf("%s, NULL,%s},\n",barinv[i],barid[i]) >>outfile
  359.     }
  360.     printf("\t{-1}\n") >>outfile
  361.     printf("};\n") >>outfile
  362. }
  363.  
  364. #-----------------------------------------------------
  365. #              選択子情報の読み込みと出力
  366. #-----------------------------------------------------
  367.  
  368. func read_selector(n)
  369. # from [ to ]
  370. {
  371.     selenum[n] = 0;
  372.     selid[n] = "0"
  373.     if (token_checknext() != "[")
  374.         return;
  375.     token_get(); # [
  376.     while (token_checknext() != "]")
  377.     {
  378.         t = token_checknext();
  379.         if (t == "id")
  380.         {
  381.             token_get();
  382.             selid[n] = itemidstr[itemidnum] = token_get();
  383.             itemidid[itemidnum] = itemid;
  384.             itemidnum++;
  385.             itemid++;
  386.         }
  387.         else if (t == "[")
  388.         {
  389.             read_selector_element(n, selenum[n]); selenum[n]++;
  390.         }
  391.         else
  392.         {
  393.             print "near line " NR ": invalid scrollbar definition"
  394.             exit
  395.         }
  396.     }
  397.     token_get(); # ]
  398. }
  399.  
  400.  
  401. func read_selector_element(n, m)
  402. # from [ to ]
  403. {
  404.     selex[n,m] = "0";
  405.     seley[n,m] = "0";
  406.     selestr[n,m] = "";
  407.     seleid[n,m] = "0"
  408.     if (token_checknext() != "[")
  409.         return;
  410.     token_get(); # [
  411.     while (1)
  412.     {
  413.         t = token_get();
  414.         if (t == "]")
  415.             break;
  416.         else if (t == "locate")
  417.             { selex[n,m]=token_get(); seley[n,m]=token_get(); }
  418.         else if (t == "string")
  419.             selestr[n,m]=token_get();
  420.         else if (t == "id")
  421.         {
  422.             itemidstr[itemidnum] = token_get();
  423.             seleid[n,m] = itemidstr[itemidnum]
  424.             itemidid[itemidnum] = itemid;
  425.             itemidnum++;
  426.             itemid++;
  427.         }
  428.         else
  429.         {
  430.             print "near line " NR ": invalid selector-element definition"
  431.             exit
  432.         }
  433.     }
  434. }
  435.  
  436.  
  437. func output_selector_elements(id, name)
  438. {
  439.     if (selenum[id] > 0)
  440.     {
  441.         printf("static SELECTOR_ELEMENT %s[] =\n", name) >>outfile
  442.         printf("{\n") >>outfile
  443.         for (j=0; j<selenum[id]; j++)
  444.         {
  445.             printf("\t{%s,%s,\"%s\",YES,NULL,%s},\n",selex[id,j],seley[id,j],
  446.                 selestr[id,j], seleid[id,j]) >>outfile
  447.         }
  448.         printf("\t{-1}\n") >>outfile
  449.         printf("};\n\n") >>outfile
  450.     }
  451. }
  452.  
  453.  
  454. func output_selectors(name, enamebase)
  455. {
  456.     printf("static SELECTOR %s[] =\n", name) >>outfile
  457.     printf("{\n") >>outfile
  458.     for (i=0; i<selnum; i++)
  459.     {
  460.         if (selenum[i] > 0)
  461.          { printf("\t{0, %s%d,NULL, NULL,%s},\n",enamebase,i, selid[i]) >>outfile }
  462.         else
  463.          { printf("\t{0, NULL,NULL, NULL,%s},\n", selid[i]) >>outfile }
  464.     }
  465.     printf("\t{-1}\n};\n") >>outfile
  466. }
  467.  
  468.  
  469. #-----------------------------------------------------
  470. #                単語の切り出し処理
  471. #-----------------------------------------------------
  472.  
  473. func nextline()
  474. {
  475.     do {
  476.         if (getline != 1)  { return -1; }
  477.         sub(/#.*/, "")
  478.     } while (match($0,/^[\t ]*$/));
  479.     tokptr = 1;
  480.     return 0;
  481. }
  482.  
  483. func token_init()
  484. {
  485.     fileend = 0;
  486.     nextline()
  487.     nexttoken = $tokptr
  488.     tokptr++
  489. }
  490.  
  491. func token_get()
  492. {
  493.     __curt = _token_get();
  494.     if (match(__curt,/^".*[^"]$/))
  495.     {
  496.         __curt = substr(__curt,2);
  497.         while(1)
  498.         {
  499.             __tt = _token_get()
  500.             if (match(__tt,/"$/))
  501.                 { __curt = __curt " " substr(__tt,1,length(__tt)-1)
  502.                   break; }
  503.             else
  504.                 __curt = __curt " " __tt;
  505.         }
  506.     }
  507.     else if (match(__curt,/^".*"$/))
  508.         __curt = substr(__curt,2,length(__curt)-2);
  509.     return __curt
  510. }
  511.  
  512. func _token_get()
  513. {
  514.     curtoken = nexttoken
  515.     if (tokptr <= NF)
  516.         nexttoken = $tokptr
  517.     else
  518.     {
  519.         if (nextline() != 0)
  520.             { fileend = 1;  nexttoken=""; }
  521.         else
  522.             nexttoken = $tokptr
  523.     }
  524.     tokptr++
  525.     return curtoken
  526. }
  527.  
  528. func token_checknext()
  529. {
  530.     return nexttoken
  531. }
  532.